package com.hamilton.erik.pt.core.util;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

public class SqlUtil {
	private static SqlUtil instance = null;
	
	public static SqlUtil getInstance() {
		if(instance == null) {
			instance = new SqlUtil();
		}
		
		return instance;
	}

	private SqlUtil() {}
	
	public static void setStringOrNull(
			int index, PreparedStatement stmt, String value) throws SQLException {
		if(value == null) {
			stmt.setNull(index, Types.NULL);
		}
		else {
			stmt.setString(index, value);
		}
	}

	public static void setLongOrNull(
			int index, PreparedStatement stmt, Long value) throws SQLException {
		if(value == null) {
			stmt.setNull(index, Types.NULL);
		}
		else {
			stmt.setLong(index, value);
		}
	}
	
	public static void setDoubleOrNull(
			int index, PreparedStatement stmt, Double value) throws SQLException {
		if(value == null) {
			stmt.setNull(index, Types.NULL);
		}
		else {
			stmt.setDouble(index, value);
		}
	}
}
